#include "wds_ui_msgbox.h"

#include "gameflow/ui_popup.h"

WDSUIMsgBox::WDSUIMsgBox() : WDSUIPopupAnimator("ui/ok.ui","WidgetOK"),
							m_pUIMsg(NULL),
							m_OkAction(ACTION_NONE),
							m_Duration(0),
							m_Delay(0)
{
	
	if(m_pPopup)
	{
		m_pAnimateWidget = m_pPopup->GetWidget("BG");
		WDSUIPopupAnimatorMgr::Instance().AddPopupAnimator(WDSUIPopupAnimatorMgr::POPUP_NAMES_MSGBOX,this);

		m_pUIMsg = m_pPopup->GetWidget("Msg");

		m_pPopup->SetWidgetFunctor("BG",UI_DELEGATE(WDSUIMsgBox, OnButtonOK));

	}

	m_Type = ANIMATION_SLIDEFROMTOP;
}


void		WDSUIMsgBox::ShowExtra(float Delay, const std::string& Msg, OK_ACTION Action)
{
	if(m_pUIMsg)
		m_pUIMsg->SetTextA(Msg);

	m_OkAction = Action;

	m_Delay = Delay;
	//Show(NULL);
}

void	WDSUIMsgBox::Tick(float dt)
{
	WDSUIPopupAnimator::Tick(dt);

	if(m_Delay > 0)
	{
		m_Delay-= dt;
		if( m_Delay <= 0)
		{
			WDSUIPopupAnimatorMgr::Instance().Show(WDSUIPopupAnimatorMgr::POPUP_NAMES_MSGBOX);
			m_Duration = 3.5f;
		}
	}
	else if ( m_Duration > 0)
	{
		m_Duration -= dt;
		if( m_Duration <= 0)
		{
			Hide();
			WDSUIAnimator::Instance().Add(m_pAnimateWidget,WDSAnimatedUI::ANIMATE_STYLE_HIDE_TOTOP,0, this);
		}
	}
}



void DELEGATE_CALL	WDSUIMsgBox::OnButtonOK(ui::UIWidget::WIDGET_EVENT Event, ui::UIWidget* pWidget)
{
	
}

void			WDSUIMsgBox::OnAnimatedUIFinish()
{
	
}

